﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Security;

namespace HQWeb.Wbserver
{
    /// <summary>
    /// Login 的摘要说明
    /// </summary>
    [WebService(Name = "TRY", Namespace = "http://tempuri.org/",Description="尝试")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class Login : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod]

        //用户登入正确登入后返回 用户名和分店 nas服务器IP地址
        public string[] UserLogin(string srtUserName,string strPW)
        {
            string  []strRsout=new string[12];
            strPW = FormsAuthentication.HashPasswordForStoringInConfigFile(strPW, "MD5").Substring(0, 18);
             BLL.SysManage.T_PUB_USER userBll = new BLL.SysManage.T_PUB_USER();
            Model.SysManage.T_PUB_USER userModel;
            userModel = userBll.GetModelByUserSymbol(srtUserName);

            if (userModel != null && userModel.PASSWORD.Equals(strPW) && userModel.ISUSED != false)
            {
                strRsout[0] = "1";                             //登入状态
                strRsout[1] = userModel.USER_ID.ToString();    //用户ID
                strRsout[2] = userModel.USER_NAME;             //用户名
                BLL.SysManage.T_PUB_BRANCH branchBll = new BLL.SysManage.T_PUB_BRANCH();
                strRsout[3] = userModel.BRANCH_ID.ToString();   //分店ID       
                Model.SysManage.T_PUB_BRANCH branchModel = branchBll.GetModel(Convert.ToInt32(userModel.BRANCH_ID));
                if (branchModel!=null)
                {
                    strRsout[4] = branchModel.NAS_IP;          //NASIP
                    strRsout[5] = branchModel.NAS_USERID;
                    strRsout[6] = branchModel.NAS_PASSWORD;
                }
                string HeadNasIP = System.Configuration.ConfigurationManager.AppSettings["HeadNASIP"];
                strRsout[7] = HeadNasIP;
                string HeadUserName = System.Configuration.ConfigurationManager.AppSettings["HeadUserName"];
                strRsout[8] = HeadUserName;
                string HeadPassword = System.Configuration.ConfigurationManager.AppSettings["HeadPassword"];
                strRsout[9] = HeadPassword;
                string ImageURL = System.Configuration.ConfigurationManager.AppSettings["ImageURL"];
                strRsout[10] = ImageURL;
                string VideoURL = System.Configuration.ConfigurationManager.AppSettings["VideoURL"];
                strRsout[11] = VideoURL;
            }
            else
            {
                strRsout[0] = "0";
            }
            return strRsout;
        }
    }
}
